package com.core.system.controller;

import com.core.system.service.ISystemDictItemService;
import com.core.system.utils.ConvertUtils;
import com.pojo.dto.SystemDictItemDto;
import com.pojo.parent.PageResp;
import com.pojo.req.RemoveReq;
import com.pojo.req.dictItem.DictItemSaveReq;
import com.utility.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author Huawei
 * @date 2024-01-05 17:13
 */
@RestController
@RequestMapping("/api/system/dictItem")
public class DictItemController {
    @Autowired
    private ISystemDictItemService dictItemService;
    /**
     * 字典类型 分页
     */
    @GetMapping("/page")
    public Result<PageResp<SystemDictItemDto>> page(@RequestParam Map<String,Object> paramMap) {
        return Result.returnCodeSuccess(dictItemService.page(paramMap));
    }

    /**
     * 字典类型 分页
     */
    @GetMapping("/list")
    public Result<List<SystemDictItemDto>> list(@RequestParam Map<String,Object> paramMap) {
        return Result.returnCodeSuccess(dictItemService.list(paramMap));
    }



    /**
     * 字典类型 inser
     */
    @PostMapping("/save")
    public Result<Object> update(@RequestBody @Validated DictItemSaveReq dictItemSaveReq) {
        dictItemService.saveOrUpdate(ConvertUtils.Convert(dictItemSaveReq, SystemDictItemDto.class));
        return Result.returnCodeSuccess();
    }


    /**
     * 字典类型 inser
     */
    @PostMapping("/remove")
    public Result<Object> remove(@RequestBody @Validated RemoveReq removeReq) {
        dictItemService.remove(removeReq.getId());
        return Result.returnCodeSuccess();
    }
}
